package com.syni.mdd.yhd.common.all.controller.protect;

/**
 * @className BmsBusinessController
 * @description 获取用户评论
 * @Author cfx
 * @DATE 2019/4/15 14:25
 * @VERSION 1.0
 **/

import com.syni.mdd.sjb.common.component.utils.common.utils.ParamsMap;
import com.syni.mdd.sjb.common.component.utils.common.annotations.CheckParams;
import com.syni.mdd.yhd.common.all.service.BmsDxCommentService;
import com.syni.mdd.yhd.common.all.utils.ParamData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/dxComment")
public class BmsDxCommentController {
    @Autowired
    BmsDxCommentService bmsDxCommentService;

    @PostMapping("/getVideoComment")
    @CheckParams(params = {"video_id","page_num","page_size"})
    public Map<String,Object> getVideoComment(@RequestBody ParamsMap paramsMap){
        Integer videoId = Integer.parseInt(paramsMap.get("video_id").toString());
        Integer pageNum = Integer.parseInt(paramsMap.get("page_num").toString());
        Integer pageSize = Integer.parseInt(paramsMap.get("page_size").toString());
        Integer commentId = paramsMap.getInteger("commentId");
        return bmsDxCommentService.findVideoComment(videoId,pageNum,pageSize,commentId);
    }


    @PostMapping("/doVideoComment")
    @CheckParams(checkAuth = true,params = {"video_id","content"})
    public Map<String,Object> doVideoComment(@RequestBody Map<String,Object> paramsMap){
        String userIdentify = paramsMap.get("userIdentify").toString();
        //评论id
        Integer commentId = null;
        //回复id
        Integer answerId = null;
        if(paramsMap.containsKey("comment_id") && !"".equals(paramsMap.get("comment_id").toString()) &&
                Integer.parseInt(paramsMap.get("comment_id").toString())!= 0){
            commentId = Integer.parseInt(paramsMap.get("comment_id").toString());
        }
        if(paramsMap.containsKey("answer_id") && !"".equals(paramsMap.get("answer_id").toString()) &&
                Integer.parseInt(paramsMap.get("answer_id").toString())!= 0){
            answerId = Integer.parseInt(paramsMap.get("answer_id").toString());
        }
        Integer videoId = Integer.parseInt(paramsMap.get("video_id").toString());
        String content = paramsMap.get("content").toString();
        Integer businessId = null;
        if(paramsMap.containsKey("business_id") && !"".equals(paramsMap.get("business_id").toString())){
            businessId = Integer.parseInt(paramsMap.get("business_id").toString());
        }
        return bmsDxCommentService.doVideoComment(Integer.parseInt(userIdentify),businessId,videoId,content,commentId,answerId);
    }
}
